package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhWebArticle;
import com.ruoyi.zsyh.service.IZsyhWebArticleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 官网新闻资讯Controller
 * 
 * @author yuexl
 * @date 2022-07-29
 */
@Controller
@RequestMapping("/zsyh/webArticle")
public class ZsyhWebArticleController extends BaseController
{
    private String prefix = "zsyh/webArticle";

    @Autowired
    private IZsyhWebArticleService zsyhWebArticleService;

    @RequiresPermissions("zsyh:webArticle:view")
    @GetMapping()
    public String webArticle()
    {
        return prefix + "/webArticle";
    }

    /**
     * 查询官网新闻资讯列表
     */
    @RequiresPermissions("zsyh:webArticle:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhWebArticle zsyhWebArticle)
    {
        startPage();
        List<ZsyhWebArticle> list = zsyhWebArticleService.selectZsyhWebArticleList(zsyhWebArticle);
        return getDataTable(list);
    }

    /**
     * 导出官网新闻资讯列表
     */
    @RequiresPermissions("zsyh:webArticle:export")
    @Log(title = "官网新闻资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhWebArticle zsyhWebArticle)
    {
        List<ZsyhWebArticle> list = zsyhWebArticleService.selectZsyhWebArticleList(zsyhWebArticle);
        ExcelUtil<ZsyhWebArticle> util = new ExcelUtil<ZsyhWebArticle>(ZsyhWebArticle.class);
        return util.exportExcel(list, "官网新闻资讯数据");
    }

    /**
     * 新增官网新闻资讯
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存官网新闻资讯
     */
    @RequiresPermissions("zsyh:webArticle:add")
    @Log(title = "官网新闻资讯", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhWebArticle zsyhWebArticle)
    {
        return toAjax(zsyhWebArticleService.insertZsyhWebArticle(zsyhWebArticle));
    }

    /**
     * 修改官网新闻资讯
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhWebArticle zsyhWebArticle = zsyhWebArticleService.selectZsyhWebArticleById(id);
        mmap.put("zsyhWebArticle", zsyhWebArticle);
        return prefix + "/edit";
    }

    /**
     * 修改保存官网新闻资讯
     */
    @RequiresPermissions("zsyh:webArticle:edit")
    @Log(title = "官网新闻资讯", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhWebArticle zsyhWebArticle)
    {
        return toAjax(zsyhWebArticleService.updateZsyhWebArticle(zsyhWebArticle));
    }

    /**
     * 删除官网新闻资讯
     */
    @RequiresPermissions("zsyh:webArticle:remove")
    @Log(title = "官网新闻资讯", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhWebArticleService.deleteZsyhWebArticleByIds(ids));
    }
}
